﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



class StrangeLandNumbers
    {
        // 100 points BG Coder
        static void Main()
        {
            string input = Console.ReadLine();

            string partial = "";
            string number = "";

            for (int i = 0; i < input.Length; i++)
            {
                partial += input[i];
                string currentDigit = IsValidNumber(partial);
                                
                if (currentDigit != "NO")
                {
                    number += currentDigit;
                    partial = "";
                }

            }

            long result = ConvertToDecimal(number);
            Console.WriteLine(result);


        }

        private static long ConvertToDecimal(string number)
        {
            long result = 0;
            for (int i = 0; i < number.Length; i++)
            {
                int digit = int.Parse(number[i].ToString());
                result += digit * (long)Math.Pow(7, number.Length - 1 - i);
                
            }
            return result;

        }

        private static string IsValidNumber(string input)
        {
            string digit = "NO";
            
                switch (input)
                {
                    case "f": digit = "0"; break;
                    case "bIN": digit = "1"; break;
                    case "oBJEC": digit = "2"; break;
                    case "mNTRAVL": digit = "3"; break;
                    case "lPVKNQ": digit = "4"; break;
                    case "pNWE": digit = "5"; break;
                    case "hT": digit = "6"; break;
                }

         
            return digit;

        }
    }

